<?php
session_start();
if(!isset($_SESSION['username'])){
	header("location: login.php");	
}
?>

<?php
require "lib/db.php";
require "lib/customer-function.php";
require "lib/case-function.php";
require "lib/category-function.php";
require "lib/subcategory-function.php";
require "lib/product-function.php";
require "lib/order-function.php";
require "lib/orderdetail-function.php";

/* pChart library inclusions */ 
 include("lib/pChart/class/pData.class.php"); 
 include("lib/pChart/class/pDraw.class.php"); 
 include("lib/pChart/class/pImage.class.php"); 
 include("lib/pChart/class/pPie.class.php"); 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Aep-Thesis</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>

<script>
	$(document).ready(function() {
      	
    });
</script>

<style>
	#content{
		overflow:scroll;
		height:510px;
		margin:1px auto;
		opacity:0.8;
		text-align:center;
	}
	
	.report{
		width:600px;
		float:left;
		margin:10px 30px;
		text-align:center;
	}
	
	.title{
		padding-top:5px;
		text-align:center;
		background:#000;
		color:#FF0;
		height:30px;
	}
	
	#customer-report,#subcategory-report{
		float:right;	
	}
	
</style>
</head>

<body>

<!--menu-->
<?php
require "menu.php";
?>

<!--content-->
<div id="content">

<!--revenue report-->
<?php
$revenueTotal = getRevenueTotal();

$revenueIn2013 = getRevenueByYear(2013);
$revenueIn2014 = getRevenueByYear(2014);

//revenue by month in year
$monthRevenueIn2013 = array();
$monthRevenueIn2014 = array();
for($i=1;$i<=12;$i++){
	$revenueMonth=getRevenueByMonthOfYear(2013,$i);
	settype($revenueMonth,"int");
	array_push($monthRevenueIn2013,$revenueMonth);	
}
for($i=1;$i<=12;$i++){
	$revenueMonth=getRevenueByMonthOfYear(2014,$i);
	settype($revenueMonth,"int");
	array_push($monthRevenueIn2014,$revenueMonth);	
}

?>
<div class="report">
	<div class="title">Revenue Report</div>
    <div id="revenue-report">
    <?php
	//draw chart
	 /* Create and populate the pData object */ 
 $MyData = new pData();   
 //$MyData->addPoints(array($revenueIn2013,$revenueIn2014),"Revenue");
 $MyData->addPoints(array($revenueIn2013,$revenueIn2014),"Revenue"); 
 
 $MyData->setAxisName(0,"Revenue (Unit: 1 Million VND)");
 //$MyData->setAxisDisplay(0,AXIS_FORMAT_CUSTOM,"YAxisFormat"); 
 //function YAxisFormat($Value) { return(round($Value/1000000,2)); } 
 //$MyData->setAxisName(0,"Revenue");//setAxistName(axistID, name)

 $MyData->addPoints(array("2013","2014"),"Years"); 
 $MyData->setSerieDescription("Years","Years"); 
 $MyData->setAbscissa("Years");
 $MyData->setAbscissaName("Years");  

 /* Create the pChart object */ 
 $myPicture = new pImage(600,320,$MyData); 

 /* Turn of Antialiasing */ 
 $myPicture->Antialias = FALSE; 

 /* Add a border to the picture */ 
 $myPicture->drawGradientArea(0,0,600,320,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100)); 
 $myPicture->drawGradientArea(0,0,600,320,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20)); 
 $myPicture->drawRectangle(0,0,599,319,array("R"=>0,"G"=>0,"B"=>0)); 

 /* Set the default font */ 
 $myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/pf_arma_five.ttf","FontSize"=>6)); 

 /* Define the chart area */ 
 $myPicture->setGraphArea( 200,50,400,280); 
 
 //draw title
 $myPicture->drawText(300,25,"Revenue By Year",array("FontSize"=>15,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); 

 /* Draw the scale */ 
 $scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,'Mode' => SCALE_MODE_START0); 
 //$myPicture->drawScale(array('Mode' => SCALE_MODE_START0));//missing array('Mode' => SCALE_MODE_START0)
 $myPicture->drawScale($scaleSettings); 


 /* Write the chart legend */ 
 $myPicture->drawLegend(450,50,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); 
 
 /* Turn on shadow computing */  
 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 

 /* Draw the chart */ 
 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 
 $settings = array("Surrounding"=>-30,"InnerSurrounding"=>30,"Interleave"=>0); 
 $myPicture->drawBarChart($settings); 

 /* Render the picture (choose the best way) */ 
 $myPicture->render("photo/chart/revenue-by-year.png");
	?>
       <table width="100%" border="1" cellspacing="0">
          <tr>
            <th>Revenue</th>
            <th>Value(Unit: 1 Million VND)</th>
          </tr>
          <tr>
            <td>2013</td>
            <td><?php echo $revenueIn2013; ?></td>
          </tr>
          <tr>
            <td>2014</td>
            <td><?php echo $revenueIn2014; ?></td>
          </tr>
          <tr>
            <td>Total</td>
            <td><?php echo $revenueTotal; ?></td>
          </tr>
        </table>
    	<img src="photo/chart/revenue-by-year.png">
        <!-- revenue by month -->
        <?php 
		/* Create and populate the pData object */ 
		 $MyData = new pData();   
		 $MyData->addPoints($monthRevenueIn2013,"2013"); 
		 $MyData->addPoints($monthRevenueIn2014,"2014"); 
		 $MyData->setAxisName(0,"Revenue (Unit: 1 Million VND)"); 
		 //$MyData->setAxisDisplay(0,AXIS_FORMAT_CUSTOM,"YAxisFormat"); 
		 $MyData->addPoints(array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"),"Months"); 
		 $MyData->setSerieDescription("Months","Month"); 
		 $MyData->setAbscissa("Months"); 
		 $MyData->setAbscissaName("Month");  
		
		 /* Create the pChart object */ 
		 $myPicture = new pImage(600,320,$MyData); 
		 $myPicture->drawGradientArea(0,0,600,320,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100)); 
		 $myPicture->drawGradientArea(0,0,600,320,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20)); 
		 $myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/pf_arma_five.ttf","FontSize"=>6)); 
		
		 /* Draw the scale  */ 
		 $myPicture->setGraphArea(70,70,580,250); 
		 $myPicture->drawScale(array("CycleBackground"=>TRUE,"DrawSubTicks"=>TRUE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10,'Mode' => SCALE_MODE_START0));
		
		 /* Turn on shadow computing */  
		 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 
		
		 /* Draw the chart */ 
		 $settings = array("Gradient"=>TRUE,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayR"=>255,"DisplayG"=>255,"DisplayB"=>255,"DisplayShadow"=>TRUE,"Surrounding"=>10);
		 $myPicture->drawBarChart($settings); 
		 
		 //draw title
 $myPicture->drawText(300,25,"Revenue By Month",array("FontSize"=>15,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); 

		
		 /* Write the chart legend */ 
		 $myPicture->drawLegend(500,60,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); 

		 /* Render the picture (choose the best way) */ 
		  $myPicture->render("photo/chart/revenue-by-month.png");
		?> 
        <table width="100%" border="1" cellspacing="0">
          <tr>
            <th colspan="2">Revenue In Year 2013</th>
          </tr>
          <tr>
            <th>Month</th>
            <th>Value(Unit: 1 Million VND)</th>
          </tr>
          <?php
		  for($i=0;$i<12;$i++){
		  ?>
          <tr>
            <td><?php echo $i+1; ?></td>
            <td><?php echo $monthRevenueIn2013[$i]; ?></td>
          </tr>
          <?php
		  }
		  ?>
        </table>
        <table width="100%" border="1" cellspacing="0">
          <tr>
            <th colspan="2">Revenue In Year 2014</th>
          </tr>
          <tr>
            <th>Month</th>
            <th>Value(Unit: 1 Million VND)</th>
          </tr>
          <?php
		  for($i=0;$i<12;$i++){
		  ?>
          <tr>
            <td><?php echo $i+1; ?></td>
            <td><?php echo $monthRevenueIn2014[$i]; ?></td>
          </tr>
          <?php
		  }
		  ?>
        </table>
         <img src="photo/chart/revenue-by-month.png">
    </div>
</div>


<!--customer report-->
<div class="report" id="customer-report">
<?php
$totalNumberOfCustomer = getTotalNumberOfCustomer();
$totalNumberOfCustomerInBronzeType = getTotalNumberOfCustomerInSpecificType(1);
$percentNumberOfCustomerInBronzeType = round($totalNumberOfCustomerInBronzeType/$totalNumberOfCustomer,2)*100;
$totalNumberOfCustomerInSilverType = getTotalNumberOfCustomerInSpecificType(2);
$percentNumberOfCustomerInSilverType = round($totalNumberOfCustomerInSilverType/$totalNumberOfCustomer,2)*100;
$totalNumberOfCustomerInGoldType = getTotalNumberOfCustomerInSpecificType(3);
$percentNumberOfCustomerInGoldType = round($totalNumberOfCustomerInGoldType/$totalNumberOfCustomer,2)*100;
$totalNumberOfCustomerInDiamondType = getTotalNumberOfCustomerInSpecificType(4);
$percentNumberOfCustomerInDiamondType = round($totalNumberOfCustomerInDiamondType/$totalNumberOfCustomer,2)*100;

//increment customer by month of year
$numberCustomerRegisterByMonthIn2013 = array();
$numberCustomerRegisterByMonthIn2014 = array();
for($i=1;$i<=12;$i++){
	$numberCustomerRegisterByMonthInYear = getNumberCustomerRegisterByMonthInYear(2013,$i);
	settype($numberCustomerRegisterByMonthInYear,"int");
	array_push($numberCustomerRegisterByMonthIn2013,$numberCustomerRegisterByMonthInYear);
}
for($i=1;$i<=12;$i++){
	$numberCustomerRegisterByMonthInYear = getNumberCustomerRegisterByMonthInYear(2014,$i);
	settype($numberCustomerRegisterByMonthInYear,"int");
	array_push($numberCustomerRegisterByMonthIn2014,$numberCustomerRegisterByMonthInYear);
}

?>

	<div class="title">Customer Report</div>
    <div >
    	<table width="100%" border="1" cellspacing="0">
          <tr>
            <th>Customer Type</th>
            <th>Number</th>
            <th>Percent(%)</th>
          </tr>
          <tr>
            <td>Bronze</td>
            <td><?php echo $totalNumberOfCustomerInBronzeType; ?></td>
            <td><?php echo $percentNumberOfCustomerInBronzeType; ?></td>
          </tr>
          <tr>
            <td>Silver</td>
            <td><?php echo $totalNumberOfCustomerInSilverType; ?></td>
            <td><?php echo $percentNumberOfCustomerInSilverType; ?></td>
          </tr>
          <tr>
            <td>Gold</td>
            <td><?php echo $totalNumberOfCustomerInGoldType; ?></td>
            <td><?php echo $percentNumberOfCustomerInGoldType; ?></td>
          </tr>
          <tr>
            <td>Diamond</td>
            <td><?php echo $totalNumberOfCustomerInDiamondType; ?></td>
            <td><?php echo $percentNumberOfCustomerInDiamondType; ?></td>
          </tr>
          <tr>
            <td>Total</td>
            <td><?php echo $totalNumberOfCustomer; ?></td>
            <td>100</td>
          </tr>
        </table>
        <?php
		/* Create and populate the pData object */ 
		 $MyData = new pData();    
		 $MyData->addPoints(array($percentNumberOfCustomerInBronzeType,$percentNumberOfCustomerInSilverType,$percentNumberOfCustomerInGoldType,$percentNumberOfCustomerInDiamondType),"ScoreA");   
		 $MyData->setSerieDescription("ScoreA","Application A"); 
		
		 /* Define the absissa serie */ 
		 $MyData->addPoints(array("Bronze","Silver","Gold","Diamond"),"Labels"); 
		 $MyData->setAbscissa("Labels"); 
		
		 /* Create the pChart object */ 
		 $myPicture = new pImage(240,180,$MyData,TRUE); 
		
		 /* Set the default font properties */  
		 $myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/Forgotte.ttf","FontSize"=>10,"R"=>80,"G"=>80,"B"=>80)); 
		
		 /* Create the pPie object */  
		 $PieChart = new pPie($myPicture,$MyData); 
		
		 /* Enable shadow computing */  
		 $myPicture->setShadow(TRUE,array("X"=>3,"Y"=>3,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 
		
		 /* Draw a splitted pie chart */  
		 $PieChart->draw3DPie(120,90,array("Radius"=>100,"DataGapAngle"=>12,"DataGapRadius"=>10,"Border"=>TRUE)); 
		
		 /* Write the legend box */  
		 $myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/Silkscreen.ttf","FontSize"=>6,"R"=>0,"G"=>0,"B"=>0)); 
		 $PieChart->drawPieLegend(10,160,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); 
		 /* Render the picture (choose the best way) */ 
		  $myPicture->render("photo/chart/percent-customer.png"); 
		?>
        <img src="photo/chart/percent-customer.png">
        
        <!--Number customer register by month -->
 
        <table width="100%" border="1" cellspacing="0">
          <tr>
            <th colspan="2">Customer Growth In 2013</th>
          </tr>
          <tr>
            <th>Month</th>
            <th>Number of registration</th>
          </tr>
          <?php
		  for($i=0;$i<12;$i++){
		  ?>
          <tr>
            <td><?php echo $i+1; ?></td>
            <td><?php echo $numberCustomerRegisterByMonthIn2013[$i]; ?></td>
          </tr>
          <?php
		  }
		  ?>
        </table>
        <table width="100%" border="1" cellspacing="0">
          <tr>
            <th colspan="2">Customer Growth In 2014</th>
          </tr>
          <tr>
            <th>Month</th>
            <th>Number of registration</th>
          </tr>
          <?php
		  for($i=0;$i<12;$i++){
		  ?>
          <tr>
            <td><?php echo $i+1; ?></td>
            <td><?php echo $numberCustomerRegisterByMonthIn2014[$i]; ?></td>
          </tr>
          <?php
		  }
		  ?>
        </table>
		<?php
		/* Create and populate the pData object */ 
		 $MyData = new pData();   
		 $MyData->addPoints($numberCustomerRegisterByMonthIn2013,"2013"); 
		 $MyData->addPoints($numberCustomerRegisterByMonthIn2014,"2014"); 
		 $MyData->setSerieWeight("2013",2); 
		 $MyData->setSerieTicks("2014",4); 
		 $MyData->setAxisName(0,"Number of registration"); 
		 $MyData->addPoints(array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"),"Months"); 
		 $MyData->setSerieDescription("Months","Month"); 
		 $MyData->setAbscissa("Months"); 
		
		 /* Create the pChart object */ 
		 $myPicture = new pImage(600,320,$MyData); 
		
		 /* Turn of Antialiasing */ 
		 $myPicture->Antialias = FALSE; 
		
		 /* Draw the background */ 
		 $Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107); 
		 $myPicture->drawFilledRectangle(0,0,600,320,$Settings); 
		
		 /* Overlay with a gradient */ 
		 $Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50); 
		 $myPicture->drawGradientArea(0,0,600,320,DIRECTION_VERTICAL,$Settings); 
		 $myPicture->drawGradientArea(0,0,600,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80)); 
		
		 /* Add a border to the picture */ 
		 $myPicture->drawRectangle(0,0,599,319,array("R"=>0,"G"=>0,"B"=>0)); 
		  
		 /* Write the chart title */  
		 $myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/Forgotte.ttf","FontSize"=>8,"R"=>255,"G"=>255,"B"=>255)); 
		 $myPicture->drawText(10,16,"Customer Growth",array("FontSize"=>11,"Align"=>TEXT_ALIGN_BOTTOMLEFT)); 
		
		 /* Set the default font */ 
		 $myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/pf_arma_five.ttf","FontSize"=>6,"R"=>0,"G"=>0,"B"=>0)); 
		
		 /* Define the chart area */ 
		 $myPicture->setGraphArea(60,40,550,200); 
		
		 /* Draw the scale */ 
		 $scaleSettings = array("XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE); 
		 $myPicture->drawScale(array('Mode' => SCALE_MODE_START0));
		
		 /* Turn on Antialiasing */ 
		 $myPicture->Antialias = TRUE; 
		
		 /* Enable shadow computing */ 
		 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 
		
		 /* Draw the line chart */ 
		 $myPicture->drawLineChart(); 
		 $myPicture->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80)); 
		
		 /* Write the chart legend */ 
		 $myPicture->drawLegend(500,9,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL,"FontR"=>255,"FontG"=>255,"FontB"=>255)); 
		
		 /* Render the picture (choose the best way) */ 
		 $myPicture->render("photo/chart/customer-growth.png"); 
		?>
        <img src="photo/chart/customer-growth.png">
    </div>
</div>

<!--subcategory -->
<?php

//subcategory
$revenueBySubCategory = array();
$listSubCategoryRevenue = array();
$listSubCategoryName = array();
$listSubCategory = getAllSubCategory();
while($subCategory = mysql_fetch_array($listSubCategory)){
	$key = $subCategory['SubCategoryName'];
	$revenueBySubCategory[$key]=$subCategory['SubCategoryAmountTotal']/1000000;
	array_push($listSubCategoryName,$subCategory['SubCategoryName']);
	array_push($listSubCategoryRevenue,$subCategory['SubCategoryAmountTotal']/1000000);
}
?>
   
<div class="report" id="subcategory-report">
       <div class="title">SubCategory Report</div>
     
        <table width="100%" border="1" cellspacing="0">
          <tr>
            <th>SubCategory Name</th>
            <th>Revenue(Unit: 1 Million VND)</th>
          </tr>
    	<?php  
		foreach($revenueBySubCategory as $key=>$value){
		?>
    	 <tr>
            <td> <?php echo $key; ?></td>
            <td><?php echo $value; ?></td>
         </tr>
        <?php  
		}
		?>
        </table>
        
        <!--subcategory chart-->
        <?php
		 /* Create and populate the pData object */ 
		 $MyData = new pData();   
		 $MyData->addPoints($listSubCategoryRevenue,"Revenue"); 
		 $MyData->setAxisName(0,"SubCategory Revenue (Unit: 1 Million VND)"); 
		 //$MyData->setAxisDisplay(0,AXIS_FORMAT_CUSTOM,"YAxisFormat"); 
		 //function YAxisFormat($Value) { return(round($Value/1000000,2)); } 
		 $MyData->addPoints($listSubCategoryName,"SubCategory"); 
		 $MyData->setSerieDescription("SubCategory","SubCategory"); 
		 $MyData->setAbscissa("SubCategory"); 
		 $MyData->setAbscissaName("SubCategory Name"); 
		
		 /* Create the pChart object */ 
		 $myPicture = new pImage(600,650,$MyData); 
		 $myPicture->drawGradientArea(0,0,600,650,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100)); 
		 $myPicture->drawGradientArea(0,0,600,650,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20)); 
		 $myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/pf_arma_five.ttf","FontSize"=>6)); 
		
		 /* Draw the chart scale */  
		 $myPicture->setGraphArea(100,80,580,630); 
		 //$myPicture->drawScale(array('Mode' => SCALE_MODE_START0));
		 $myPicture->drawScale(array("CycleBackground"=>TRUE,"DrawSubTicks"=>TRUE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10,"Pos"=>SCALE_POS_TOPBOTTOM,'Mode' => SCALE_MODE_START0)); 
		
		 /* Turn on shadow computing */  
		 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 
		
		 /* Create the per bar palette */ 
		 $Palette = array("0"=>array("R"=>188,"G"=>224,"B"=>46,"Alpha"=>100), 
						  "1"=>array("R"=>224,"G"=>100,"B"=>46,"Alpha"=>100), 
						  "2"=>array("R"=>224,"G"=>214,"B"=>46,"Alpha"=>100), 
						  "3"=>array("R"=>46,"G"=>151,"B"=>224,"Alpha"=>100), 
						  "4"=>array("R"=>176,"G"=>46,"B"=>224,"Alpha"=>100), 
						  "5"=>array("R"=>224,"G"=>46,"B"=>117,"Alpha"=>100), 
						  "6"=>array("R"=>92,"G"=>224,"B"=>46,"Alpha"=>100), 
						  "7"=>array("R"=>224,"G"=>176,"B"=>46,"Alpha"=>100)); 
		
		 /* Draw the chart */  
		 $myPicture->drawBarChart(array("DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"Rounded"=>TRUE,"Surrounding"=>30,"OverrideColors"=>$Palette)); 
		 
		 $myPicture->drawText(300,35,"Revenue By SubCategory",array("FontSize"=>15,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
		
		 /* Write the legend */  
		// $myPicture->drawLegend(570,215,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); 
		
		 /* Render the picture (choose the best way) */ 
		 $myPicture->render("photo/chart/subcategory-revenue.png"); 
		?>
        <img src="photo/chart/subcategory-revenue.png">
</div>

<!--category, subcategory, product report-->

<?php
//category
$revenueByCategory = array();
$listCategoryName = array();
$listCategoryRevenue = array();
$listCategory = getAllCategory();
while($category = mysql_fetch_array($listCategory)){
	$key = $category['CategoryName'];
	$revenueByCategory[$key]=$category['CategoryAmountTotal']/1000000;
	array_push($listCategoryName,$category['CategoryName']);
	array_push($listCategoryRevenue,$category['CategoryAmountTotal']/1000000);
}

?>
<!--category -->
<div class="report">
	<div class="title">Category Report</div>
	<div id="item-report">
    	
  		<table width="100%" border="1" cellspacing="0">
          <tr>
            <th>Category Name</th>
            <th>Revenue(Unit: 1 Million VND)</th>
          </tr>
     	<?php  
		foreach($revenueByCategory as $key=>$value){
		?>
        <tr>
            <td> <?php echo $key; ?></td>
            <td><?php echo $value; ?></td>
         </tr>
        <?php  
		}
		?>
        </table>
        
         <!--category chart-->
        <?php
		 /* Create and populate the pData object */ 
		 $MyData = new pData();   
		 //$MyData->addPoints(array($revenueIn2013,$revenueIn2014),"Revenue");
		 $MyData->addPoints($listCategoryRevenue,"Revenue"); 
		 
		 $MyData->setAxisName(0,"Category Revenue");
		// $MyData->setAxisDisplay(0,AXIS_FORMAT_CUSTOM,"YAxisFormat"); 
		// function YAxisFormat($Value) { return(round($Value/1000000,2)." Mil VND"); } 
		 $MyData->setAxisName(0," Category Revenue");//setAxistName(axistID, name)
		
		 //$MyData->addPoints($listCategoryName,"Categorys");
		 $MyData->addPoints(array("Utensil","Hóa Phẩm","May Mặc","TP Tươi Sống","TP Công Nghệ"),"Categorys");  
		 $MyData->setSerieDescription("Categorys","Category"); 
		 $MyData->setAbscissa("Categorys"); 
		
		 /* Create the pChart object */ 
		 $myPicture = new pImage(600,320,$MyData); 
		
		 /* Turn of Antialiasing */ 
		 $myPicture->Antialias = FALSE; 
		
		 /* Add a border to the picture */ 
		 $myPicture->drawGradientArea(0,0,600,320,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100)); 
		 $myPicture->drawGradientArea(0,0,600,320,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20)); 
		 $myPicture->drawRectangle(0,0,599,319,array("R"=>0,"G"=>0,"B"=>0)); 
		
		 /* Set the default font */ 
		 $myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/pf_arma_five.ttf","FontSize"=>6)); 
		
		 /* Define the chart area */ 
		 $myPicture->setGraphArea( 60,50,580,280); 
		 
		 //draw title
		 $myPicture->drawText(300,25,"Revenue By Category",array("FontSize"=>15,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); 
		
		 /* Draw the scale */ 
		 $scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,'Mode' => SCALE_MODE_START0); 
		 //$myPicture->drawScale(array('Mode' => SCALE_MODE_START0));//missing array('Mode' => SCALE_MODE_START0)
		 $myPicture->drawScale($scaleSettings); 
		
		
		 /* Write the chart legend */ 
		 $myPicture->drawLegend(450,50,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); 
		 
		 /* Turn on shadow computing */  
		 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 
		
		 /* Draw the chart */ 
		 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 
		 $settings = array("Surrounding"=>-30,"InnerSurrounding"=>30,"Interleave"=>0); 
		 $myPicture->drawBarChart($settings); 
		 /* Render the picture (choose the best way) */ 
		 $myPicture->render("photo/chart/category-revenue.png"); 
		?>
        <img src="photo/chart/category-revenue.png">
      </div>
</div>

<!--case report-->
<div class="report" id="case-report">
<?php
$totalNumberOfCase = getTotalNumberOfCase();
$numberOfNewCase = getNumberOfCaseByStatus(1);
$percentNumberOfNewCase = round($numberOfNewCase/$totalNumberOfCase,2)*100;
$numberOfInProgressCase = getNumberOfCaseByStatus(2);
$percentNumberOfInProgressCase = round($numberOfInProgressCase/$totalNumberOfCase,2)*100;
$numberOfDoneCase = getNumberOfCaseByStatus(3);
$percentNumberOfDoneCase = round($numberOfDoneCase/$totalNumberOfCase,2)*100;
?>
	<div class="title">Case Report</div>
	<div >
    	<table width="100%" border="1" cellspacing="0">
          <tr>
            <th>Case Type</th>
            <th>Number</th>
            <th>Percent(%)</th>
          </tr>
          <tr>
            <td>New</td>
            <td><?php echo $numberOfNewCase; ?></td>
            <td><?php echo $percentNumberOfNewCase; ?></td>
          </tr>
          <tr>
            <td>In-progress</td>
            <td><?php echo $numberOfInProgressCase; ?></td>
            <td><?php echo $percentNumberOfInProgressCase; ?></td>
          </tr>
          <tr>
            <td>Done</td>
            <td><?php echo $numberOfDoneCase; ?></td>
            <td><?php echo $percentNumberOfDoneCase; ?></td>
          </tr>
          <tr>
            <td>Total</td>
            <td><?php echo $totalNumberOfCase; ?></td>
            <td>100</td>
          </tr>
        </table>
        
        <!--case chart-->
        <?php
		/* Create and populate the pData object */ 
		 $MyData = new pData();    
		 $MyData->addPoints(array($percentNumberOfNewCase,$percentNumberOfInProgressCase,$percentNumberOfDoneCase),"Percent");   
		 $MyData->setSerieDescription("Percent","Application A"); 
		
		 /* Define the absissa serie */ 
		 $MyData->addPoints(array("New","In-Progress","Done"),"Labels"); 
		 $MyData->setAbscissa("Labels"); 
		
		 /* Create the pChart object */ 
		 $myPicture = new pImage(600,260,$MyData); 
		
		 /* Draw a solid background */ 
		 $Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107); 
		 $myPicture->drawFilledRectangle(0,0,600,300,$Settings); 
		
		 /* Overlay with a gradient */ 
		 $Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50); 
		 $myPicture->drawGradientArea(0,0,600,260,DIRECTION_VERTICAL,$Settings); 
		 $myPicture->drawGradientArea(0,0,600,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>100)); 
		
		 /* Add a border to the picture */ 
		 $myPicture->drawRectangle(0,0,599,259,array("R"=>0,"G"=>0,"B"=>0)); 
		
		 /* Write the picture title */  
		 $myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/Silkscreen.ttf","FontSize"=>6)); 
		 $myPicture->drawText(10,13,"Percent of Case Status ",array("R"=>255,"G"=>255,"B"=>255)); 
		
		 /* Set the default font properties */  
		 $myPicture->setFontProperties(array("FontName"=>"lib/pChart/fonts/Forgotte.ttf","FontSize"=>10,"R"=>80,"G"=>80,"B"=>80)); 
		
		 /* Enable shadow computing */  
		 $myPicture->setShadow(TRUE,array("X"=>2,"Y"=>2,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>50)); 
		
		 /* Create the pPie object */  
		 $PieChart = new pPie($myPicture,$MyData); 
		
		 /* Draw an AA pie chart */  
		 $PieChart->draw2DRing(320,140,array("WriteValues"=>TRUE,"ValueR"=>255,"ValueG"=>255,"ValueB"=>255,"Border"=>TRUE)); 
		
		 /* Write the legend box */  
		 $myPicture->setShadow(FALSE); 
		 $PieChart->drawPieLegend(30,40,array("Alpha"=>20)); 
		
		 /* Render the picture (choose the best way) */ 
		 $myPicture->render("photo/case-chart.png"); 
		?>
        <img src="photo/case-chart.png">
    </div>
</div>


<!--top 20 product has highest revenue-->
<?php
//product
$revenueByProduct = array();
$listTop20Product = getTop20Product();
while($product = mysql_fetch_array($listTop20Product)){
	$key = $product['ProductName'];
	$revenueByProduct[$key]=$product['ProductAmountTotal']/1000000;
}
?>
<div class="report" id="product-report">
       <div class="title">Product Report</div>
        <table width="100%" border="1" cellspacing="0">
          <tr>
            <th colspan="2">Top 20 products have the highest revenue</th>
          </tr>
          <tr>
            <th>Product Name</th>
            <th>Revenue(Unit: 1 Million VND)</th>
          </tr>
    	<?php  
		foreach($revenueByProduct as $key=>$value){
		?>
    	 <tr>
            <td> <?php echo $key; ?></td>
            <td><?php echo $value; ?></td>
         </tr>
        <?php  
		}
		?>
        </table>
</div>

        
</div>
<!--footer-->
<?php
require "footer.php";
?>

</body>
</html>